<template>
  <div class="custom-body" :style="borderStyle">
    <div class="custom-header" :style="titleStyle">
      <div v-for="(item,index) in menuList" :key="'item-'+index" class="custom-header-ul-li" :style="defaultColor">
        <div
          class="header-ul-li-body"
          :style="(active === index || hoverActive === index)? activeStyle: ''"
          @mouseover="mouseOver(index)"
          @mouseout="mouseOut"
          @click="headerClick(index,item)"
        >{{ item.label }}</div>
      </div>
    </div>
    <div class="custom-content">
      <div class="custom-content-left">
        <organization-fl v-if="menuClick.value === 'custom-org'" ref="parent" :column="column" @callBack="callBackOrganizationLeft" />
        <menu-fl v-else ref="parent" :column="column" @callBack="callBackLeft" />
      </div>
      <div class="custom-content-right">
        <organization-service v-if="menuClick.value === 'custom-org'" ref="menu" :column="column" :parent="parent" :dx="menuClick.value" />
        <menu-service v-else ref="menu" :column="column" :parent="parent" :dx="menuClick.value" @callBack="callBackRight" @fact-entity="entityOpen" />
      </div>
    </div>
  </div>
</template>
<script>
import MenuFl from '@/common/service/fl/menu'
import OrganizationFl from '@/common/service/fl/organization'
import MenuService from '@/common/service/content/fl'
import OrganizationService from '@/common/service/content/organization'
export default {
  name: 'PortalNewPcCustomServiceV1',
  components: { MenuFl, MenuService, OrganizationFl, OrganizationService },
  props: {
    temp: {
      type: Object,
      default() {
        return {}
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      column: null,
      dataList: [],
      active: 0,
      menuList: [],
      hoverActive: null,
      activeStyle: {},
      defaultColor: {},
      parent: {},
      dx: {},
      menuClick: {},
      customStyle: {},
      titleStyle: {},
      bodyStyle: {},
      titleFont: {}
    }
  },
  computed: {
    borderStyle() {
      if (this.temp.sfxsbk === true) {
        return { border: '1px solid #eeeeee', backgroundColor: this.customStyle.mrzt, opacity: this.customStyle.tmd, color: this.customStyle.fontColor }
      }
      if (this.temp.bkyy === true) {
        return { boxShadow: '0 2px 4px rgba(0, 0, 0, .12)', backgroundColor: this.customStyle.mrzt, opacity: this.customStyle.tmd, color: this.customStyle.fontColor }
      }
      return { backgroundColor: this.customStyle.mrzt, opacity: this.customStyle.tmd, color: this.customStyle.fontColor }
    }
  },
  watch: {
    layout: {
      handler(newData, oldData) {
        this.customStyle = newData
        this.titleStyle = { backgroundColor: newData.mrlb, opacity: newData.tmd }
        this.titleFont = { color: newData.lmys }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    temp: {
      handler(newData, oldData) {
        if (this.showHeader) {
          const pzx = JSON.parse(newData.data.pzx)
          this.column = pzx
          this.menuList = pzx.data // 获取导航信息
          this.menuClick = this.menuList[0] // 默认加载第一个
          this.defaultColor = { color: pzx.fontColor }
          this.activeStyle = { borderBottom: '2px solid ' + pzx.theme, color: pzx.theme }
        } else {
          const pzx = JSON.parse(newData.pzx)
          this.column = pzx
          this.menuList = pzx.data
          this.menuClick = this.menuList[0] // 默认加载第一个
          this.defaultColor = { color: pzx.fontColor }
          this.activeStyle = { borderBottom: '2px solid ' + pzx.theme, color: pzx.theme }
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    headerClick(obj, item) {
      this.active = obj
      this.menuClick = item
      this.parent = {}
      this.$nextTick(() => {
        this.$refs.menu.init(item)
        this.$refs.parent.init()
      })
    },
    entityOpen(data) {
      if (this.column.isOpenEntity) { // 允许打开详情页
        if (this.column.entityOpenType === 1) { // 地址参数的方式打开
          window.open(data[this.column.entityUrl], '_blank')
        }
        if (this.column.entityOpenType === 2) { // 地址传参查询
          if (undefined !== this.column.params && this.column.params !== null && this.column.params.length > 0) {
            let url = this.column.entityUrl
            this.column.params.forEach(item => {
              url = url.replace(new RegExp('\\$\\{([\\s]*?)(' + item.code + '{1})([\\s]*?)([^}])*\\}'), data[item.column])
            })
            window.open(url, '_blank')
          }
        }
        if (this.column.entityOpenType === 3) { // 采用自定义模版的方式打开
          const params = []
          if (undefined !== this.column.entityParams && this.column.entityParams !== null && this.column.entityParams.length > 0) {
            this.column.entityParams.forEach(item => {
              const obj = { code: item.code, value: data[item.value] }
              params.push(obj)
            })
          }
          const object = { params: params, setting: this.temp, entityTemp: this.column.entityTemplateId, temp: this.column.entityTemp, showMenu: false }
          this.$emit('fetch-entity', object)
        }
      }
    },
    mouseOver(obj) {
      this.hoverActive = obj
    },
    callBackLeft(data) {
      this.parent = data
    },
    callBackOrganizationLeft(data) {
      this.parent = data
    },
    callBackRight(data) {},
    mouseOut() {
      this.hoverActive = { color: this.column.fontColor }
    }
  }
}
</script>
<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-flow: column nowrap;
  background-color: #ffffff;
  border-radius: 4px;
  box-sizing: border-box;
  overflow: hidden;
}
.custom-header {
  width: 100%;
  height: 3.5rem;
  flex: 0 1 auto;
  display: flex;
  flex-flow: row nowrap;
  border-bottom: 1px solid #e2e2e2;
}
.custom-header-ul-li {
  width: 12.5rem;
  text-align: center;
  font-size: 1.125rem;
  line-height: 3.5rem;
  font-weight: 600;
  position: relative;
  padding:0px 10px;
  box-sizing: border-box;
}
.header-ul-li-body {
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.custom-content {
  width: 100%;
  height: auto;
  flex: 1 1 auto;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-flow: row nowrap;
  border-left: 1px solid #e2e2e2;
  border-right: 1px solid #e2e2e2;
  border-bottom: 1px solid #e2e2e2;
}
.custom-content-left {
  width: 15.5rem;
  flex: 0 1 auto;
  border-right: 1px solid #e2e2e2;
}
.custom-content-right {
  flex: 1 1 auto;
}

</style>
